<?php

/**
 * @copyright 2012
 */
require_once("db_common.php");
require_once ("XMLUtils.php");
class Category
{
    
    function Init($categoryid)
    {
        $sql = "select * from category where category_id = '$categoryid'";
    
        if($query = mysql_query($sql))
        {
            $row = mysql_fetch_array($query);
            //print_r($row);
            $this->name = $row['category_name'];
            $this->id = $row['category_id'];
            $this->imgid = $row['category_img_id'];
            $this->type = $row['category_type'];
        } else 
        {
            echo "categoryid = " + $categoryid;
            output_mysqlerror();
        }
    }
    
    function Update()
    {
        if($this->id){
            $sql = "update category set category_name = '$this->name',category_img_id = '$this->imgid',
                     category_type = '$this->type' where category_id = '$this->id'";
            if($query = mysql_query($sql))
            {
                
            } else 
            {
                  echo "id = " + $categoryid;
                  output_mysqlerror();
            }
        } else 
        {
            echo "$categoryid is empty In category::Update";
        }
    }
    
    function GetXMLNode($doc)
    {
        $s = $doc->createElement("category");
       // $r->appendChild($s);
  
        AppendNewTextNode($doc, "type", $this->type, $s);
        AppendNewTextNode($doc, "id", $this->id, $s);
        AppendNewTextNode($doc, "imgid", $this->imgid, $s);
        AppendNewTextNode($doc, "name", $this->name, $s);
        
        return $s;
    }
    
    var $id;
    var $type;
    var $imgid;
    var $name;
    
}



?>